package com.clt.ess.gjzw;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.clt.ess.service.impl.GjzwServiceImpl;
import com.clt.ess.gjzw.domain.applyRandom.ApplyRandomRequest;
import com.clt.ess.gjzw.domain.applyRandom.ApplyRandomResponse;
import com.clt.ess.utils.HttpUtils;
import org.bouncycastle.util.encoders.Hex;

import java.util.HashMap;
import java.util.Map;

public class HttpTest {


    public static void main1(String[] args) {
        String appKey = "343a12a4-6733-4a9e-9d6d-5e45208d9dc8";
        //租户账号
        String tenantCode = "D62U110ZH001";
        //租户密码
        String password = "62110001";
        String secret = tenantCode + "#" + appKey + "#" + password;

        byte[] md = new byte[32];
        byte[] psw = secret.getBytes();
//            SM3Digest sm3 = new SM3Digest();
        SM3Utils sm3Utils = new SM3Utils();
        sm3Utils.update(psw, 0, psw.length);
        sm3Utils.doFinal(md, 0);
        String sm3Sign = new String(Hex.encode(md));

        Map<String, String> params = new HashMap<>();
        params.put("appkey", appKey);
        params.put("username", tenantCode);
        params.put("sign", sm3Sign);

//      59.255.22.72:8081
        String ss = HttpUtils.post("http://59.255.22.72:8081/aic/rest/service/safety/refreshsecret", params);

        JSONObject aa = JSON.parseObject(ss);

        String aesDncode = SymmetricEncoder.AESDncode(appKey, aa.getString("data"));

        System.out.println(aesDncode);

    }

    public static void main(String[] args) {
        String certBase64 = "MIID7TCCA5CgAwIBAgIIPfUAygAE7SswDAYIKoEcz1UBg3UFADBpMQswCQYDVQQGEwJDTjE8MDoGA1UECgwzTmF0aW9uYWwgRS1Hb3Zlcm5tZW50IE5ldHdvcmsgQWRtaW5pc3RyYXRpb24gQ2VudGVyMRwwGgYDVQQDDBNDRUdOIFNNMiBDbGFzcyAyIENBMB4XDTE5MDYyNzA2NTQzNVoXDTI0MDYyNTA2NTQzNVowczELMAkGA1UEBhMCQ04xEjAQBgNVBAgMCeWMl+S6rOW4gjEeMBwGA1UECgwV5Lit5Zu954Of6I2J5oC75YWs5Y+4MTAwLgYDVQQ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Object = new JSONObject();
        jsonObject.put("taskCode","applyServiceRandom");
        jsonObject.put("version","1.0");
        jsonObject.put("applicantCert",certBase64);
        jsonObject.put("randomA","1234567812345678");

        map.put("data",jsonObject.toJSONString());

        String a  = HttpUtils.HttpPostWithJson("http://59.255.128.6:9794/sealCertService",jsonObject.toJSONString());

    }
}
